package smartgrid.modules.trade;

public class Contract {
	
	// Contract identification
	private int			id;
	
	// Contract time
	private int			time;
	
	// Energy seller
	private int			supplier;
	
	// Energy buyer
	private int			buyer;
	
	// Offered quantity of energy
	private double	qtyOffered;
	
	// Demanded quantity of energy
	private double	qtyDemanded;
	
	// Price of the offered unit energy
	private double	unitPrice;
	
	// Quantity of supplied energy
	private double	qtySupplied;
	
	// Quantity of consumed energy
	private double	qtyConsumed;
	
	// Energy transacted
	private double	qtyTransacted;
	
	// Total price
	private double	totalPrice;
	
	// Status complied
	private boolean	complied;
	
	
	public Contract(int id, int time, int supplier, int buyer, double qtyOffered,
			double qtyDemanded, double unitPrice) {
		this.id = id;
		this.time = time;
		this.supplier = supplier;
		this.buyer = buyer;
		this.qtyOffered = qtyOffered;
		this.qtyDemanded = qtyDemanded;
		this.unitPrice = unitPrice;
		this.qtySupplied = 0.0;
		this.qtyConsumed = 0.0;
		this.qtyTransacted = 0.0;
		this.totalPrice = 0.0;
		this.complied = false;
	}
	
	
	public int getId() {
		return this.id;
	}
	
	
	public int getTime() {
		return this.time;
	}
	
	
	public int getSupplier() {
		return this.supplier;
	}
	
	
	public int getBuyer() {
		return this.buyer;
	}
	
	
	public double getQtyOffered() {
		return this.qtyOffered;
	}
	
	
	public double getQtyDemanded() {
		return this.qtyDemanded;
	}
	
	
	public double getUnitPrice() {
		return this.unitPrice;
	}
	
	
	public double getQtySupplied() {
		return this.qtySupplied;
	}
	
	
	public void setQtySupplied(double qtySupplied) {
		this.qtySupplied = qtySupplied;
		this.qtyTransacted = Math.min(this.qtySupplied, this.qtyConsumed);
	}
	
	
	public double getQtyConsumed() {
		return this.qtyConsumed;
	}
	
	
	public void setQtyConsumed(double qtyConsumed) {
		this.qtyConsumed = qtyConsumed;
		this.qtyTransacted = Math.min(this.qtySupplied, this.qtyConsumed);
	}
	
	
	public double getTotalPrice() {
		return this.totalPrice;
	}
	
	
	public void setTotalPrice() {
		this.totalPrice = Math.min(this.qtySupplied, this.qtyConsumed)
				* this.unitPrice;
	}
	
	
	public double getQtyTransacted() {
		return this.qtyTransacted;
	}
	
	
	public boolean getComplied() {
		return this.complied;
	}
	
	
	public void setComplied(boolean complied) {
		this.complied = complied;
	}
	
	
	@Override
	public String toString() {
		String str = new String();
		
		str += "[CONTRACT] " + this.id + " " + this.supplier + " " + this.buyer
				+ " " + this.qtyOffered + " " + this.qtyDemanded + " "
				+ this.qtySupplied + " " + this.qtyConsumed + " " + this.totalPrice
				+ " " + this.unitPrice + " " + this.complied;
		
		return str;
	}
}